package com.cema.manage.project.manage.withdrawalConfig.controller;

import java.util.ArrayList;
import java.util.List;

import cn.hutool.core.util.StrUtil;
import com.cema.manage.common.utils.StringUtils;
import com.cema.manage.framework.web.domain.BaseEntity;
import com.cema.manage.project.enums.RedisEnum;
import com.cema.manage.project.manage.withdrawalConfig.domain.WithdrawalConfig;
import com.cema.manage.project.manage.withdrawalConfig.service.IWithdrawalConfigService;
import com.cema.manage.redis.RedisService;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.cema.manage.framework.web.controller.BaseController;
import com.cema.manage.framework.web.domain.Message;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.cema.manage.framework.web.page.TableDataInfo;

import javax.annotation.Resource;


/**
 * 提现金额配置 信息操作处理
 *
 * @author reasahi
 * @date 2024-07-27
 */
@Controller
@RequestMapping("/manage/withdrawalConfig")
public class WithdrawalConfigController extends BaseController {
    private String prefix = "manage/withdrawalConfig";

    @Autowired
    private IWithdrawalConfigService withdrawalConfigService;


    @GetMapping("{id}")
    @RequiresPermissions("manage:withdrawalConfig:view")
    public String withdrawalConfig(@PathVariable("id") Integer id, Model model) {
        model.addAttribute("uvChannel", id);
        return prefix + "/withdrawalConfig";
    }

    /**
     * 查询提现金额配置列表
     */
    @RequiresPermissions("manage:withdrawalConfig:list")
    @ResponseBody
    @PostMapping("/list")
    public TableDataInfo list(WithdrawalConfig withdrawalConfig) {
        startPage();
        EntityWrapper<WithdrawalConfig> entityWrapper = new EntityWrapper<>();
        entityWrapper.setEntity(withdrawalConfig);
        List<WithdrawalConfig> list = withdrawalConfigService.selectList(entityWrapper);
        return getDataTable(list);
    }

    /**
     * 新增提现金额配置
     */
    @RequiresPermissions("manage:withdrawalConfig:add")
    @GetMapping("/add/{id}")
    public String add(@PathVariable("id") Integer id, Model model) {
        model.addAttribute("uvChannel", id);
        return prefix + "/add";
    }

    /**
     * 修改提现金额配置
     */
    @RequiresPermissions("manage:withdrawalConfig:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, Model model) {
        WithdrawalConfig withdrawalConfig = withdrawalConfigService.selectById(id);
        model.addAttribute("withdrawalConfig", withdrawalConfig);
        return prefix + "/edit";
    }

    /**
     * 保存提现金额配置
     */
    @RequiresPermissions("manage:withdrawalConfig:save")
    @PostMapping("/save")
    @ResponseBody
    public Message save(WithdrawalConfig withdrawalConfig) {
        Integer id = withdrawalConfig.getId();
        if (StringUtils.isNotNull(id)) {
            if (withdrawalConfigService.updateById(withdrawalConfig)) {
                return Message.success();
            }
            return Message.error();
        } else {
            if (withdrawalConfigService.insert(withdrawalConfig)) {
                return Message.success();
            }
            return Message.error();
        }
    }

    /**
     * 删除提现金额配置
     */
    @RequiresPermissions("manage:withdrawalConfig:remove")
    @PostMapping("/remove/{id}")
    @ResponseBody
    public Message remove(@PathVariable("id") Integer id) {
        if (withdrawalConfigService.deleteById(id)) {
            return Message.success();
        }
        return Message.error();
    }

    /**
     * 批量删除提现金额配置
     */
    @RequiresPermissions("manage:withdrawalConfig:batchRemove")
    @PostMapping("/batchRemove")
    @ResponseBody
    public Message remove(@RequestParam("ids[]") Integer[] ids) {
        List list = new ArrayList();
        for (Integer n : ids) {
            list.add(n);
        }
        if (withdrawalConfigService.deleteBatchIds(list)) {
            return Message.success();
        }
        return Message.error();
    }

}
